package com.example.Administrator.shoujiweishi.fragments;

import android.content.Intent;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.Administrator.shoujiweishi.MyApplication;
import com.example.Administrator.shoujiweishi.R;
import com.example.Administrator.shoujiweishi.activities.Insert_contacts;
import com.example.Administrator.shoujiweishi.activities.adapter.ShowAllAdapter;
import com.example.Administrator.shoujiweishi.activities.adapter.Twofragadapter;
import com.example.Administrator.shoujiweishi.fragments.base.BaseFragment;
import com.example.Administrator.shoujiweishi.utils.ActivityCollecter;
import com.example.Administrator.shoujiweishi.utils.MyUtil;
import com.example.Administrator.shoujiweishi.vo.Contact;

import java.util.ArrayList;
import java.util.List;

public class TwoFragment extends BaseFragment {
    RecyclerView secendrecy;
    List<Contact> list;
    Twofragadapter myAdapter;
    @Override
    public int getContentXML() {
        return R.layout.activity_two_fragment;
    }

    @Override
    public void initData() {

    }
    @Override
    public void initView() {
        final ImageView img_insert_sos= (ImageView) getthisview().findViewById(R.id.img_insert_sos);
        final Button btn_insert_sos= (Button) getthisview().findViewById(R.id.btn_insert_sos);
        final EditText edit_insert_sos= (EditText) getthisview().findViewById(R.id.edit_insert_sos);
        secendrecy= (RecyclerView) getthisview().findViewById(R.id.second_recyclerview);
        getthisview().findViewById(R.id.img_insert_sos).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().startActivity(new Intent(getActivity(), Insert_contacts.class));
            }
        });

        getthisview().findViewById(R.id.btn_insert_sos).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list= MyUtil.getAllContact();
                String edtext=edit_insert_sos.getText().toString();
                edit_insert_sos.setText("");

                img_insert_sos.setVisibility(View.VISIBLE);
                btn_insert_sos.setVisibility(View.INVISIBLE);

                list= MyUtil.getAllContact();

                secendrecy.setLayoutManager(new LinearLayoutManager(getActivity()));
                secendrecy.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL));
                myAdapter = new Twofragadapter(list);
                secendrecy.setAdapter(myAdapter);

            }
        });




        edit_insert_sos.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                    img_insert_sos.setVisibility(View.INVISIBLE);
                    btn_insert_sos.setVisibility(View.VISIBLE);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}
